![]() |
PATH![]() |
![]() ![]() |
A stay-open script application handles incoming commands even if it is already running a handler in response to a previous command. This means that execution of a handler can be interrupted while another handler is run. Because script applications are not multithreaded, execution of the first handler pauses until the second one finishes. This is known as "last-in, first-out" event handling.
This can cause problems if both handlers modify the same script property or global variable or if both attempt to modify an application's data. For example, suppose that running a script application named increment causes it to increment the property p for several minutes:
property p : 0
on close
set temp to p
set p to 0
return temp
end close
set p to 0
repeat 1000000 times
set p to p + 1
end repeat
If this script application receives a Close command while it is running:
tell application "Increment" to close
AppleScript can't deal with such interruptions automatically.